package realQuestion.didi;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;

public class Class208 {


    class Trie {
          HashMap <String,String> map;
          LinkedList<String>  list;
        public Trie() {
            map=new HashMap<>();
            list=new LinkedList<>();
        }
        public void insert(String word) {
            map.put(word,"");
            list.addLast(word);
        }

        public boolean search(String word) {
            return map.containsKey(word);

        }

        public boolean startsWith(String prefix) {
            Set<String> set = map.keySet();
            Iterator<String> iterator = set.iterator();
            while (iterator.hasNext()){
                String cur = iterator.next();
                boolean b = cur.startsWith(prefix);
                if (b){
                    return  true;
                }
            }
            return  false;

        }

    }

    public static void main(String[] args) {
        Class208 class208 = new Class208();
        Trie trie =class208.new Trie();
        trie.insert("apple");
        System.out.println(trie.search("apple"));
        System.out.println(trie.search("app"));
        System.out.println(trie.startsWith("app"));
        trie.insert("app");
        System.out.println(trie.search("app"));

    }

}
